package com.nxu.comtrol;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.cj.Session;
import com.nxu.dao.DoctorDao;
import com.nxu.service.DoctorService;
import com.nxu.service.impl.DoctorServiceImpl;
import com.nxu.util.SqlSessionFactoryUtil;

/**
 * Servlet implementation class DoctorSelectReservable
 */
@WebServlet("/doctorSelectReservable")
public class DoctorSelectReservable extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoctorSelectReservable() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session=request.getSession();
		String dname=(String) session.getAttribute("dname");
		
		DoctorService doctorservice= new DoctorServiceImpl();
		List<Date> list=doctorservice.selectReservableDoctor(dname);
		
		List<String> list2 =new ArrayList<String>();
		
		for(int i=0;i<list.size();i++) {
			 SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd");
		     String val = time.format(list.get(i));
		     //Date类型转String类型
		 	 list2.add(val);
		}
			 
			 
		 request.setAttribute("DoctorList", list2);
		
		 
		 
		 if(list!=null) {
			 request.getRequestDispatcher("/jsp/Reservable.jsp").forward(request,response);
			}else {
		     request.getRequestDispatcher("/jsp/doctor.jsp").forward(request,response);
			}
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
